{% extends '@YesknAdmin/base.html.twig' %}

{% block page_wraper %}
    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header">{{ entityName }}管理 <small>{{ entitySubTitle }}</small>
                <span class="pull-right">
                    {% if form is not empty %}
                        {% if create_btn is not empty %}
                            <a href="{{ path(create_btn) }}" class="btn btn-success"><i class="fa fa-plus"></i> 增加</a>
                        {% else %}
                            <button class="btn btn-success" data-toggle="modal" data-target="#entityModal"><i class="fa fa-plus"></i> 增加</button>
                        {% endif %}
                    {% endif %}
            </span>
            </h3>
        </div>
    </div>

    {% if searchForm %}
        {% include '@YesknAdmin/crud/search-form.html.twig' with {
            form: searchForm
        }%}
    {% endif %}

    <div class="row">
        <div class="col-lg-12">
            <table width="100%" class="table table-striped table-hover" style="table-layout: fixed">
                <thead>
                <tr>
                    {% for key, column in columns %}
                        {% set lkey = key %}
                        <th {% if column_width[key] is defined %}width="{{ column_width[key] }}%"{% endif %}>{{ column }}</th>
                    {% endfor %}
                    {% if extra.hide_options_column is empty %}
                        <th {% if column_width[columns|length] is defined %}width="{{ column_width[columns|length] }}%"{% endif %}>操作</th>
                    {% endif %}
                </tr>
                </thead>
                <tbody>
                {% for key, item in list %}
                    <tr>
                        {% for key, one in item %}
                            {%  set columnAttr = extra.columnAttr[key] is defined ? extra.columnAttr[key] : ''  %}
                            <td {{ columnAttr }}>{{ one|raw }}</td>
                        {% endfor %}
                        {% if extra.hide_options_column is empty %}
                            <td style="width: 10%" align="center">
                                <div class="btn-group" role="group" aria-label="...">
                                    {% if edit_btn is not empty %}
                                        <a role="button" class="btn btn-warning btn-sm" href="{{ path('yeskn_admin_post_edit', {id: entity,id:ids[key]}) }}"><i class="fa fa-edit"></i> 编辑</a>
                                    {% else %}
                                        <a data-edit role="button" class="btn btn-warning btn-sm" href="{{ path('admin_edit', {entity: entity,id:ids[key]}) }}"><i class="fa fa-edit"></i> 编辑</a>
                                    {% endif %}
                                    <a data-delete role="button" class="btn btn-danger btn-sm" href="{{ path('admin_delete',{entity: entity, id:ids[key]}) }}"><i class="fa fa-remove"></i> 删除</a>
                                </div>
                            </td>
                        {% endif %}
                    </tr>
                {% endfor %}
                </tbody>
            </table>


            <div style="display: flex;align-items:center">
                {% include '@YesknAdmin/pagination.html.twig' with {
                    entity: entity,
                    pageData: {
                        pageNo: app.request.query.get('pageNo', 1),
                        pageSize: app.request.query.get('pageSize', 20),
                        allPage: allPage,
                    }
                } %}
            </div>
        </div>
    </div>

    {% if form is not empty %}
        {% include '@YesknAdmin/modals/entity-modal.html.twig' with {
            form: form,
            action: path('admin_edit', {entity: entity}),
            title: '增加' ~ entityName
        } %}
    {% endif %}

{% endblock %}

{% block footer_javascript %}
    {% include '@YesknAdmin/crud/footer-javascript-crud.html.twig' with {
        entity: entity
    } %}
{% endblock %}
